/* eslint-disable max-lines */
import * as api from './api';
import {createNotificationAction} from 'Shared/utils/serverNotification';
import {
    getCurrentUserPagePermissionsSuccess,
    getCurrentUserPagePermissionsFail,
    getCurrentUserPagePermissionsApi
} from 'Shared/actions/currentUserContext';
import {PAGE_CODE, PERMISSION} from './constants';
import {piProformaInvoiceStatus, saleOrderBusinessType, salesConfirmationStatus, saleOrderStatus} from './utils';

/*==============================通知通告API================================= */
export const GET_NOTICE_DATA_BEGIN = 'GET_NOTICE_DATA_BEGIN';
export const GET_NOTICE_DATA_SUCCESS = 'GET_NOTICE_DATA_SUCCESS';
export const GET_NOTICE_DATA_FAIL = 'GET_NOTICE_DATA_FAIL';

const getNoticeDataBegin = () => ({
    type: GET_NOTICE_DATA_BEGIN
});

const getNoticeDataSuccess = data => ({
    type: GET_NOTICE_DATA_SUCCESS,
    data
});

const getNoticeDataFail = createNotificationAction(message => ({
    type: GET_NOTICE_DATA_FAIL,
    message
}));
export const getNoticeData = () => dispatch => {
    dispatch(getNoticeDataBegin());
    return api.getNoticeData().then(res => {
        if(res.ok)
            dispatch(getNoticeDataSuccess(res.data.notices));
        else
            dispatch(getNoticeDataFail());
    });
};
/*==============================保修结算API================================= */
export const GET_CLAIMSETTLEMENT_DATA_BEGIN = 'GET_CLAIMSETTLEMENT_DATA_BEGIN';
export const GET_CLAIMSETTLEMENT_DATA_SUCCESS = 'GET_CLAIMSETTLEMENT_DATA_SUCCESS';
export const GET_CLAIMSETTLEMENT_DATA_FAIL = 'GET_CLAIMSETTLEMENT_DATA_FAIL';

const getClaimSettlementDataBegin = () => ({
    type: GET_CLAIMSETTLEMENT_DATA_BEGIN
});

const getClaimSettlementDataSuccess = data => ({
    type: GET_CLAIMSETTLEMENT_DATA_SUCCESS,
    data
});

const getClaimSettlementDataFail = createNotificationAction(message => ({
    type: GET_CLAIMSETTLEMENT_DATA_FAIL,
    message
}));
export const getClaimSettlementData = () => dispatch => {
    dispatch(getClaimSettlementDataBegin());
    return api.getClaimSettlementData().then(res => {
        if(res.ok)
            dispatch(getClaimSettlementDataSuccess(res.data.claimSettlements));
        else
            dispatch(getClaimSettlementDataFail());
    });
};
/*==============================待维护工时API================================= */
export const GET_WORKITEM_DATA_BEGIN = 'GET_WORKITEM_DATA_BEGIN';
export const GET_WORKITEM_DATA_SUCCESS = 'GET_WORKITEM_DATA_SUCCESS';
export const GET_WORKITEM_DATA_FAIL = 'GET_WORKITEM_DATA_FAIL';

const getWorkItemDataBegin = () => ({
    type: GET_WORKITEM_DATA_BEGIN
});

const getWorkItemDataSuccess = data => ({
    type: GET_WORKITEM_DATA_SUCCESS,
    data
});

const getWorkItemDataFail = createNotificationAction(message => ({
    type: GET_WORKITEM_DATA_FAIL,
    message
}));
export const getWorkItemData = () => dispatch => {
    dispatch(getWorkItemDataBegin());
    return api.getWorkItemData().then(res => {
        if(res.ok)
            dispatch(getWorkItemDataSuccess(res.data.workItems));
        else
            dispatch(getWorkItemDataFail());
    });
};

/*==============================扣补款API================================= */
export const GET_EXPENSE_DATA_BEGIN = 'GET_EXPENSE_DATA_BEGIN';
export const GET_EXPENSE_DATA_SUCCESS = 'GET_EXPENSE_DATA_SUCCESS';
export const GET_EXPENSE_DATA_FAIL = 'GET_EXPENSE_DATA_FAIL';

const getExpenseDataBegin = () => ({
    type: GET_EXPENSE_DATA_BEGIN
});

const getExpenseDataSuccess = data => ({
    type: GET_EXPENSE_DATA_SUCCESS,
    data
});

const getExpenseDataFail = createNotificationAction(message => ({
    type: GET_EXPENSE_DATA_FAIL,
    message
}));
export const getExpenseData = () => dispatch => {
    dispatch(getExpenseDataBegin());
    return api.getExpenseAdjustmentData().then(res => {
        if(res.ok)
            dispatch(getExpenseDataSuccess(res.data.expenseAdjustments));
        else
            dispatch(getExpenseDataFail());
    });
};
/*==============================待维护辅料的备件API================================= */
export const GET_ASSISTPART_DATA_BEGIN = 'GET_ASSISTPART_DATA_BEGIN';
export const GET_ASSISTPART_DATA_SUCCESS = 'GET_ASSISTPARTDATA_SUCCESS';
export const GET_ASSISTPART_DATA_FAIL = 'GET_ASSISTPART_DATA_FAIL';

const getAssistPartDataBegin = () => ({
    type: GET_ASSISTPART_DATA_BEGIN
});

const getAssistPartDataSuccess = data => ({
    type: GET_ASSISTPART_DATA_SUCCESS,
    data
});

const getAssistPartDataFail = createNotificationAction(message => ({
    type: GET_ASSISTPART_DATA_FAIL,
    message
}));
export const getAssistPartData = () => dispatch => {
    dispatch(getAssistPartDataBegin());
    return api.getUserDefinedAssistPartData().then(res => {
        if(res.ok)
            dispatch(getAssistPartDataSuccess(res.data.assistParts));
        else
            dispatch(getAssistPartDataFail());
    });
};
/*==============================待维护当月索赔价的备件API================================= */
export const GET_SERVICEPRICE_DATA_BEGIN = 'GET_SERVICEPRICE_DATA_BEGIN';
export const GET_SERVICEPRICE_DATA_SUCCESS = 'GET_SERVICEPRICE_DATA_SUCCESS';
export const GET_SERVICEPRICE_DATA_FAIL = 'GET_SERVICEPRICE_DATA_FAIL';

const getServicePriceDataBegin = () => ({
    type: GET_SERVICEPRICE_DATA_BEGIN
});

const getServicePriceDataSuccess = data => ({
    type: GET_SERVICEPRICE_DATA_SUCCESS,
    data
});

const getServicePriceDataFail = createNotificationAction(message => ({
    type: GET_SERVICEPRICE_DATA_FAIL,
    message
}));
export const getServicePriceData = () => dispatch => {
    dispatch(getServicePriceDataBegin());
    return api.getPartServicePriceData().then(res => {
        if(res.ok)
            dispatch(getServicePriceDataSuccess(res.data.servicePrices));
        else
            dispatch(getServicePriceDataFail());
    });
};

/*==============================备件需求计划提报提醒API================================= */
export const GET_PARTORDERPLAN_DATA_BEGIN = 'GET_PARTORDERPLAN_DATA_BEGIN';
export const GET_PARTORDERPLAN_DATA_SUCCESS = 'GET_PARTORDERPLAN_DATA_SUCCESS';
export const GET_PARTORDERPLAN_DATA_FAIL = 'GET_PARTORDERPLAN_DATA_FAIL';

const getPartOrderPlanDataBegin = () => ({
    type: GET_PARTORDERPLAN_DATA_BEGIN
});

const getPartOrderPlanDataSuccess = data => ({
    type: GET_PARTORDERPLAN_DATA_SUCCESS,
    data
});

const getPartOrderPlanDataFail = createNotificationAction(message => ({
    type: GET_PARTORDERPLAN_DATA_FAIL,
    message
}));
export const getPartOrderPlanData = () => dispatch => {
    dispatch(getPartOrderPlanDataBegin());
    return api.getPartOrderPlanData().then(res => {
        if(res.ok)
            dispatch(getPartOrderPlanDataSuccess(res.data.existData));
        else
            dispatch(getPartOrderPlanDataFail());
    });
};
/*==============================Back order确认提醒API================================= */
export const GET_PARTBACKORDER_DATA_BEGIN = 'GET_PARTBACKORDER_DATA_BEGIN';
export const GET_PARTBACKORDER_DATA_SUCCESS = 'GET_PARTBACKORDER_DATA_SUCCESS';
export const GET_PARTBACKORDER_DATA_FAIL = 'GET_PARTBACKORDER_DATA_FAIL';

const getPartBackOrderDataBegin = () => ({
    type: GET_PARTBACKORDER_DATA_BEGIN
});

const getPartBackOrderDataSuccess = data => ({
    type: GET_PARTBACKORDER_DATA_SUCCESS,
    data
});

const getPartBackOrderDataFail = createNotificationAction(message => ({
    type: GET_PARTBACKORDER_DATA_FAIL,
    message
}));
export const getPartBackOrderData = () => dispatch => {
    dispatch(getPartBackOrderDataBegin());
    return api.getPartBackOrderData().then(res => {
        if(res.ok)
            dispatch(getPartBackOrderDataSuccess(res.data.quantityDatas));
        else
            dispatch(getPartBackOrderDataFail());
    });
};
/*==============================导入经销库存数据提醒API================================= */
export const GET_PARTSTOCK_DATA_BEGIN = 'GET_PARTSTOCK_DATA_BEGIN';
export const GET_PARTSTOCK_DATA_SUCCESS = 'GET_PARTSTOCK_DATA_SUCCESS';
export const GET_PARTSTOCK_DATA_FAIL = 'GET_PARTSTOCK_DATA_FAIL';

const getPartStockDataBegin = () => ({
    type: GET_PARTSTOCK_DATA_BEGIN
});

const getPartStockDataSuccess = data => ({
    type: GET_PARTSTOCK_DATA_SUCCESS,
    data
});

const getPartStockDataFail = createNotificationAction(message => ({
    type: GET_PARTSTOCK_DATA_FAIL,
    message
}));
export const getPartStockData = () => dispatch => {
    dispatch(getPartStockDataBegin());
    return api.getPartStockData().then(res => {
        if(res.ok)
            dispatch(getPartStockDataSuccess(res.data.existData));
        else
            dispatch(getPartStockDataFail());
    });
};
/*==============================待审核预申请结算API================================= */
export const GET_CLAIMAPPLY_DATA_BEGIN = 'GET_CLAIMAPPLY_DATA_BEGIN';
export const GET_CLAIMAPPLY_DATA_SUCCESS = 'GET_CLAIMAPPLY_DATA_SUCCESS';
export const GET_CLAIMAPPLY_DATA_FAIL = 'GET_CLAIMAPPLY_DATA_FAIL';

const getClaimApplyDataBegin = () => ({
    type: GET_CLAIMAPPLY_DATA_BEGIN
});

const getClaimApplyDataSuccess = data => ({
    type: GET_CLAIMAPPLY_DATA_SUCCESS,
    data
});

const getClaimApplyDataFail = createNotificationAction(message => ({
    type: GET_CLAIMAPPLY_DATA_FAIL,
    message
}));
export const getClaimApplyData = () => dispatch => {
    dispatch(getClaimApplyDataBegin());
    return api.getClaimApplyData().then(res => {
        if(res.ok)
            dispatch(getClaimApplyDataSuccess(res.data.claimApplies));
        else
            dispatch(getClaimApplyDataFail());
    });
};

/*==============================整车滚动计划未提报通知API================================= */
export const GET_SALEPLANORDER_SUBMIT_BEGIN = 'GET_SALEPLANORDER_SUBMIT_BEGIN';
export const GET_SALEPLANORDER_SUBMIT_SUCCESS = 'GET_SALEPLANORDER_SUBMIT_SUCCESS';
export const GET_SALEPLANORDER_SUBMIT_FAIL = 'GET_SALEPLANORDER_SUBMIT_FAIL';

const getSalePlanOrderSubmitBegin = () => ({
    type: GET_SALEPLANORDER_SUBMIT_BEGIN
});

const getSalePlanOrderSubmitSuccess = data => ({
    type: GET_SALEPLANORDER_SUBMIT_SUCCESS,
    data
});

const getSalePlanOrderSubmitFail = createNotificationAction(message => ({
    type: GET_SALEPLANORDER_SUBMIT_FAIL,
    message
}));
export const getSalePlanOrderSubmit = () => dispatch => {
    dispatch(getSalePlanOrderSubmitBegin());
    return api.getSalePlanOrderSubmit().then(res => {
        if(res.ok)
            dispatch(getSalePlanOrderSubmitSuccess(res.data));
        else
            dispatch(getSalePlanOrderSubmitFail());
    });
};
/*==============================整车滚动计划未审批通知API================================= */
export const GET_SALEPLANORDER_APPROVE_BEGIN = 'GET_SALEPLANORDER_APPROVE_BEGIN';
export const GET_SALEPLANORDER_APPROVE_SUCCESS = 'GET_SALEPLANORDER_APPROVE_SUCCESS';
export const GET_SALEPLANORDER_APPROVE_FAIL = 'GET_SALEPLANORDER_APPROVE_FAIL';

const getSalePlanOrderApproveBegin = () => ({
    type: GET_SALEPLANORDER_APPROVE_BEGIN
});

const getSalePlanOrderApproveSuccess = data => ({
    type: GET_SALEPLANORDER_APPROVE_SUCCESS,
    data
});

const getSalePlanOrderApproveFail = createNotificationAction(message => ({
    type: GET_SALEPLANORDER_APPROVE_FAIL,
    message
}));
export const getSalePlanOrderApprove = () => dispatch => {
    dispatch(getSalePlanOrderApproveBegin());
    return api.getSalePlanOrderApprove().then(res => {
        if(res.ok)
            dispatch(getSalePlanOrderApproveSuccess(res.data));
        else
            dispatch(getSalePlanOrderApproveFail());
    });
};
/*==============================备件需求计划驳回提醒API================================= */
export const GET_PARTORDERPLAN_REJECT_BEGIN = 'GET_PARTORDERPLAN_REJECT_BEGIN';
export const GET_PARTORDERPLAN_REJECT_SUCCESS = 'GET_PARTORDERPLAN_REJECT_SUCCESS';
export const GET_PARTORDERPLAN_REJECT_FAIL = 'GET_PARTORDERPLAN_REJECT_FAIL';

const getPartOrderPlanRejectBegin = () => ({
    type: GET_PARTORDERPLAN_REJECT_BEGIN
});

const getPartOrderPlanRejectSuccess = data => ({
    type: GET_PARTORDERPLAN_REJECT_SUCCESS,
    data
});

const getPartOrderPlanRejectFail = createNotificationAction(message => ({
    type: GET_PARTORDERPLAN_REJECT_FAIL,
    message
}));
export const getPartOrderPlanReject = () => dispatch => {
    dispatch(getPartOrderPlanRejectBegin());
    return api.getPartOrderPlanReject().then(res => {
        if(res.ok)
            dispatch(getPartOrderPlanRejectSuccess(res.data.partOrderPlan));
        else
            dispatch(getPartOrderPlanRejectFail());
    });
};
/*==============================备件需求计划审核提醒API================================= */
export const GET_PARTORDERPLAN_APPROVE_BEGIN = 'GET_PARTORDERPLAN_APPROVE_BEGIN';
export const GET_PARTORDERPLAN_APPROVE_SUCCESS = 'GET_PARTORDERPLAN_APPROVE_SUCCESS';
export const GET_PARTORDERPLAN_APPROVE_FAIL = 'GET_PARTORDERPLAN_APPROVE_FAIL';

const getPartOrderPlanApproveBegin = () => ({
    type: GET_PARTORDERPLAN_APPROVE_BEGIN
});

const getPartOrderPlanApproveSuccess = data => ({
    type: GET_PARTORDERPLAN_APPROVE_SUCCESS,
    data
});

const getPartOrderPlanApproveFail = createNotificationAction(message => ({
    type: GET_PARTORDERPLAN_APPROVE_FAIL,
    message
}));
export const getPartOrderPlanApprove = () => dispatch => {
    dispatch(getPartOrderPlanApproveBegin());
    return api.getPartOrderPlanApprove().then(res => {
        if(res.ok)
            dispatch(getPartOrderPlanApproveSuccess(res.data));
        else
            dispatch(getPartOrderPlanApproveFail());
    });
};
/*==============================备件销售订单驳回提醒API================================= */
export const GET_PARTSALEORDER_REJECT_BEGIN = 'GET_PARTSALEORDER_REJECT_BEGIN';
export const GET_PARTSALEORDER_REJECT_SUCCESS = 'GET_PARTSALEORDER_REJECT_SUCCESS';
export const GET_PARTSALEORDER_REJECT_FAIL = 'GET_PARTSALEORDER_REJECT_FAIL';

const getPartSaleOrderRejectBegin = () => ({
    type: GET_PARTSALEORDER_REJECT_BEGIN
});

const getPartSaleOrderRejectSuccess = data => ({
    type: GET_PARTSALEORDER_REJECT_SUCCESS,
    data
});

const getPartSaleOrderRejectFail = createNotificationAction(message => ({
    type: GET_PARTSALEORDER_REJECT_FAIL,
    message
}));
export const getPartSaleOrderReject = () => dispatch => {
    dispatch(getPartSaleOrderRejectBegin());
    return api.getPartSaleOrderReject().then(res => {
        if(res.ok)
            dispatch(getPartSaleOrderRejectSuccess(res.data.partSaleOrder));
        else
            dispatch(getPartSaleOrderRejectFail());
    });
};
/*==============================备件销售订单审核提醒API================================= */
export const GET_PARTSALEORDER_APPROVE_BEGIN = 'GET_PARTSALEORDER_APPROVE_BEGIN';
export const GET_PARTSALEORDER_APPROVE_SUCCESS = 'GET_PARTSALEORDER_APPROVE_SUCCESS';
export const GET_PARTSALEORDER_APPROVE_FAIL = 'GET_PARTSALEORDER_APPROVE_FAIL';

const getPartSaleOrderApproveBegin = () => ({
    type: GET_PARTSALEORDER_APPROVE_BEGIN
});

const getPartSaleOrderApproveSuccess = data => ({
    type: GET_PARTSALEORDER_APPROVE_SUCCESS,
    data
});

const getPartSaleOrderApproveFail = createNotificationAction(message => ({
    type: GET_PARTSALEORDER_APPROVE_FAIL,
    message
}));
export const getPartSaleOrderApprove = () => dispatch => {
    dispatch(getPartSaleOrderApproveBegin());
    return api.getPartSaleOrderApprove().then(res => {
        if(res.ok)
            dispatch(getPartSaleOrderApproveSuccess(res.data));
        else
            dispatch(getPartSaleOrderApproveFail());
    });
};
/*==============================PI确认提醒API================================= */
export const GET_PARTORDERPI_CONFIRM_BEGIN = 'GET_PARTORDERPI_CONFIRM_BEGIN';
export const GET_PARTORDERPI_CONFIRM_SUCCESS = 'GET_PARTORDERPI_CONFIRM_SUCCESS';
export const GET_PARTORDERPI_CONFIRM_FAIL = 'GET_PARTORDERPI_CONFIRM_FAIL';

const getPartOrderPIConfirmBegin = () => ({
    type: GET_PARTORDERPI_CONFIRM_BEGIN
});

const getPartOrderPIConfirmSuccess = data => ({
    type: GET_PARTORDERPI_CONFIRM_SUCCESS,
    data
});

const getPartOrderPIConfirmFail = createNotificationAction(message => ({
    type: GET_PARTORDERPI_CONFIRM_FAIL,
    message
}));
export const getPartOrderPIConfirm = () => dispatch => {
    dispatch(getPartOrderPIConfirmBegin());
    return api.getPartOrderPIConfirm().then(res => {
        if(res.ok)
            dispatch(getPartOrderPIConfirmSuccess(res.data.partOrderPI));
        else
            dispatch(getPartOrderPIConfirmFail());
    });
};
/*==============================PI付款提醒API================================= */
export const GET_PARTORDERPI_PAY_BEGIN = 'GET_PARTORDERPI_PAY_BEGIN';
export const GET_PARTORDERPI_PAY_SUCCESS = 'GET_PARTORDERPI_PAY_SUCCESS';
export const GET_PARTORDERPI_PAY_FAIL = 'GET_PARTORDERPI_PAY_FAIL';

const getPartOrderPIPayBegin = () => ({
    type: GET_PARTORDERPI_PAY_BEGIN
});

const getPartOrderPIPaySuccess = data => ({
    type: GET_PARTORDERPI_PAY_SUCCESS,
    data
});

const getPartOrderPIPayFail = createNotificationAction(message => ({
    type: GET_PARTORDERPI_PAY_FAIL,
    message
}));
export const getPartOrderPIPay = () => dispatch => {
    dispatch(getPartOrderPIPayBegin());
    return api.getPartOrderPIPay().then(res => {
        if(res.ok)
            dispatch(getPartOrderPIPaySuccess(res.data.partOrderPI));
        else
            dispatch(getPartOrderPIPayFail());
    });
};
/*==============================PI生成提醒API================================= */
export const GET_PARTSALEORDER_CREATE_BEGIN = 'GET_PARTSALEORDER_CREATE_BEGIN';
export const GET_PARTSALEORDER_CREATE_SUCCESS = 'GET_PARTSALEORDER_CREATE_SUCCESS';
export const GET_PARTSALEORDER_CREATE_FAIL = 'GET_PARTSALEORDER_CREATE_FAIL';

const getPartSaleOrderCreateBegin = () => ({
    type: GET_PARTSALEORDER_CREATE_BEGIN
});

const getPartSaleOrderCreateSuccess = data => ({
    type: GET_PARTSALEORDER_CREATE_SUCCESS,
    data
});

const getPartSaleOrderCreateFail = createNotificationAction(message => ({
    type: GET_PARTSALEORDER_CREATE_FAIL,
    message
}));
export const getPartSaleOrderCreate = () => dispatch => {
    dispatch(getPartSaleOrderCreateBegin());
    return api.getPartSaleOrderCreate().then(res => {
        if(res.ok)
            dispatch(getPartSaleOrderCreateSuccess(res.data));
        else
            dispatch(getPartSaleOrderCreateFail());
    });
};
/*==============================备货需求生成提醒API================================= */
export const GET_PARTORDERPI_CREATE_BEGIN = 'GET_PARTORDERPI_CREATE_BEGIN';
export const GET_PARTORDERPI_CREATE_SUCCESS = 'GET_PARTORDERPI_CREATE_SUCCESS';
export const GET_PARTORDERPI_CREATE_FAIL = 'GET_PARTORDERPI_CREATE_FAIL';

const getPartOrderPICreateBegin = () => ({
    type: GET_PARTORDERPI_CREATE_BEGIN
});

const getPartOrderPICreateSuccess = data => ({
    type: GET_PARTORDERPI_CREATE_SUCCESS,
    data
});

const getPartOrderPICreateFail = createNotificationAction(message => ({
    type: GET_PARTORDERPI_CREATE_FAIL,
    message
}));
export const getPartOrderPICreate = () => dispatch => {
    dispatch(getPartOrderPICreateBegin());
    return api.getPartOrderPICreate().then(res => {
        if(res.ok)
            dispatch(getPartOrderPICreateSuccess(res.data));
        else
            dispatch(getPartOrderPICreateFail());
    });
};
/*==============================备货需求上传SAP提醒API================================= */
export const GET_STOCKREQUIREMENT_UPLOAD_BEGIN = 'GET_STOCKREQUIREMENT_UPLOAD_BEGIN';
export const GET_STOCKREQUIREMENT_UPLOAD_SUCCESS = 'GET_STOCKREQUIREMENT_UPLOAD_SUCCESS';
export const GET_STOCKREQUIREMENT_UPLOAD_FAIL = 'GET_STOCKREQUIREMENT_UPLOAD_FAIL';

/*==============================PI确认提醒（KD）API================================= */
export const GET_INVOICEADDKD_SUCCESS = 'GET_INVOICEADDKD_SUCCESS';
const getInvoiceAddKdSuccess = data => ({
    type: GET_INVOICEADDKD_SUCCESS,
    data
});
export const getInvoiceAddKd = () => dispatch =>
    api.getSaleProformaInvoice({
        status: piProformaInvoiceStatus.新建,
        businessType: saleOrderBusinessType.KD
    }).then(res => {
        if(res.ok)
            dispatch(getInvoiceAddKdSuccess(res.data));
    });
/*==============================PI确认提醒（CBU）API================================= */
export const GET_INVOICEADDCBU_SUCCESS = 'GET_INVOICEADDCBU_SUCCESS';
const getInvoiceAddCbuSuccess = data => ({
    type: GET_INVOICEADDCBU_SUCCESS,
    data
});
export const getInvoiceAddCbu = () => dispatch =>
    api.getSaleProformaInvoice({
        status: piProformaInvoiceStatus.新建,
        businessType: saleOrderBusinessType.CBU
    }).then(res => {
        if(res.ok)
            dispatch(getInvoiceAddCbuSuccess(res.data));
    });

/*==============================PI已确认提醒（KD）API================================= */
export const GET_INVOICECONFIRMKD_SUCCESS = 'GET_INVOICECONFIRMKD_SUCCESS';
const getInvoiceConfirmKdSuccess = data => ({
    type: GET_INVOICECONFIRMKD_SUCCESS,
    data
});
export const getInvoiceConfirmKd = () => dispatch =>
    api.getSaleProformaInvoice({
        status: piProformaInvoiceStatus.确认,
        businessType: saleOrderBusinessType.KD
    }).then(res => {
        if(res.ok)
            dispatch(getInvoiceConfirmKdSuccess(res.data));
    });

/*==============================PI已确认提醒（CBU）API================================= */
export const GET_INVOICECONFIRMCBU_SUCCESS = 'GET_INVOICECONFIRMCBU_SUCCESS';
const getInvoiceConfirmCbuSuccess = data => ({
    type: GET_INVOICECONFIRMCBU_SUCCESS,
    data
});
export const getInvoiceConfirmCbu = () => dispatch =>
    api.getSaleProformaInvoice({
        status: piProformaInvoiceStatus.确认,
        businessType: saleOrderBusinessType.CBU
    }).then(res => {
        if(res.ok)
            dispatch(getInvoiceConfirmCbuSuccess(res.data));
    });

/*==============================销售订单驳回提醒（CBU））API================================= */
export const GET_CBUSALEORDERREJECT_SUCCESS = 'GET_CBUSALEORDERREJECT_SUCCESS';
const getCBUSaleOrderRejectSuccess = data => ({
    type: GET_CBUSALEORDERREJECT_SUCCESS,
    data
});
export const getCBUSaleOrderReject = () => dispatch =>
    api.getSaleOrder({
        status: saleOrderStatus.审核不通过,
        businessType: saleOrderBusinessType.CBU
    }).then(res => {
        if(res.ok)
            dispatch(getCBUSaleOrderRejectSuccess(res.data));
    });
/*==============================销售订单驳回提醒（KD））API================================= */
export const GET_KDSALEORDERREJECT_SUCCESS = 'GET_KDSALEORDERREJECT_SUCCESS';
const getKDSaleOrderRejectSuccess = data => ({
    type: GET_KDSALEORDERREJECT_SUCCESS,
    data
});
export const getKDSaleOrderReject = () => dispatch =>
    api.getSaleOrder({
        status: saleOrderStatus.审核不通过,
        businessType: saleOrderBusinessType.KD
    }).then(res => {
        if(res.ok)
            dispatch(getKDSaleOrderRejectSuccess(res.data));
    });
/*==============================销售确认书驳回提醒（CBU））API================================= */
export const GET_SALECONFIRMATIONREJECTCBU_SUCCESS = 'GET_SALECONFIRMATIONREJECTCBU_SUCCESS';
const getSaleConfirmationRejectCbuSuccess = data => ({
    type: GET_SALECONFIRMATIONREJECTCBU_SUCCESS,
    data
});
export const getSaleConfirmationRejectCbu = () => dispatch =>
    api.getSaleConfirmation({
        status: salesConfirmationStatus.审核不通过,
        businessType: saleOrderBusinessType.CBU
    }).then(res => {
        if(res.ok)
            dispatch(getSaleConfirmationRejectCbuSuccess(res.data));
    });
/*==============================销售确认书驳回提醒（KD））API================================= */
export const GET_SALECONFIRMATIONREJECTKD_SUCCESS = 'GET_SALECONFIRMATIONREJECTKD_SUCCESS';
const getSaleConfirmationRejectKdSuccess = data => ({
    type: GET_SALECONFIRMATIONREJECTKD_SUCCESS,
    data
});
export const getSaleConfirmationRejectKd = () => dispatch =>
    api.getSaleConfirmation({
        status: salesConfirmationStatus.审核不通过,
        businessType: saleOrderBusinessType.KD
    }).then(res => {
        if(res.ok)
            dispatch(getSaleConfirmationRejectKdSuccess(res.data));
    });

    
/*==============================备件索赔单驳回提醒API================================= */
export const GET_PARTCLAIM_REJECT_BEGIN = 'GET_PARTCLAIM_REJECT_BEGIN';
export const GET_PARTCLAIM_REJECT_SUCCESS = 'GET_PARTCLAIM_REJECT_SUCCESS';
export const GET_PARTCLAIM_REJECT_FAIL = 'GET_PARTCLAIM_REJECT_FAIL';

const getPartClaimRejectBegin = () => ({
    type: GET_PARTCLAIM_REJECT_BEGIN
});

const getPartClaimRejectSuccess = data => ({
    type: GET_PARTCLAIM_REJECT_SUCCESS,
    data
});

const getPartClaimRejectFail = createNotificationAction(message => ({
    type: GET_PARTCLAIM_REJECT_FAIL,
    message
}));
export const getPartClaimReject = () => dispatch => {
    dispatch(getPartClaimRejectBegin());
    return api.getPartClaimReject().then(res => {
        if(res.ok)
            dispatch(getPartClaimRejectSuccess(res.data.partClaim));
        else
            dispatch(getPartClaimRejectFail());
    });
};
/*==============================备件索赔判定书确认提醒API================================= */
export const GET_PARTCLAIMDECISION_CONFIRM_BEGIN = 'GET_PARTCLAIMDECISION_CONFIRM_BEGIN';
export const GET_PARTCLAIMDECISION_CONFIRM_SUCCESS = 'GET_PARTCLAIMDECISION_CONFIRM_SUCCESS';
export const GET_PARTCLAIMDECISION_CONFIRM_FAIL = 'GET_PARTCLAIMDECISION_CONFIRM_FAIL';

const getPartClaimDecisionConfirmBegin = () => ({
    type: GET_PARTCLAIMDECISION_CONFIRM_BEGIN
});

const getPartClaimDecisionConfirmSuccess = data => ({
    type: GET_PARTCLAIMDECISION_CONFIRM_SUCCESS,
    data
});

const getPartClaimDecisionConfirmFail = createNotificationAction(message => ({
    type: GET_PARTCLAIMDECISION_CONFIRM_FAIL,
    message
}));
export const getPartClaimDecisionConfirm = () => dispatch => {
    dispatch(getPartClaimDecisionConfirmBegin());
    return api.getPartClaimDecisionConfirm().then(res => {
        if(res.ok)
            dispatch(getPartClaimDecisionConfirmSuccess(res.data.partClaimDecision));
        else
            dispatch(getPartClaimDecisionConfirmFail());
    });
};
/*==============================备件索赔发票确认提醒API================================= */
export const GET_PARTCLAIMCACU_CONFIRM_BEGIN = 'GET_PARTCLAIMCACU_CONFIRM_BEGIN';
export const GET_PARTCLAIMCACU_CONFIRM_SUCCESS = 'GET_PARTCLAIMCACU_CONFIRM_SUCCESS';
export const GET_PARTCLAIMCACU_CONFIRM_FAIL = 'GET_PARTCLAIMCACU_CONFIRM_FAIL';

const getPartClaimCacuConfirmBegin = () => ({
    type: GET_PARTCLAIMCACU_CONFIRM_BEGIN
});

const getPartClaimCacuConfirmSuccess = data => ({
    type: GET_PARTCLAIMCACU_CONFIRM_SUCCESS,
    data
});

const getPartClaimCacuConfirmFail = createNotificationAction(message => ({
    type: GET_PARTCLAIMCACU_CONFIRM_FAIL,
    message
}));
export const getPartClaimCacuConfirm = () => dispatch => {
    dispatch(getPartClaimCacuConfirmBegin());
    return api.getPartClaimCacuConfirm().then(res => {
        if(res.ok)
            dispatch(getPartClaimCacuConfirmSuccess(res.data.partClaimCacu));
        else
            dispatch(getPartClaimCacuConfirmFail());
    });
};
/*==============================备件索赔单审核提醒API================================= */
export const GET_PARTCLAIM_APPROVE_BEGIN = 'GET_PARTCLAIM_APPROVE_BEGIN';
export const GET_PARTCLAIM_APPROVE_SUCCESS = 'GET_PARTCLAIM_APPROVE_SUCCESS';
export const GET_PARTCLAIM_APPROVE_FAIL = 'GET_PARTCLAIM_APPROVE_FAIL';

const getPartClaimApproveBegin = () => ({
    type: GET_PARTCLAIM_APPROVE_BEGIN
});

const getPartClaimApproveSuccess = data => ({
    type: GET_PARTCLAIM_APPROVE_SUCCESS,
    data
});

const getPartClaimApproveFail = createNotificationAction(message => ({
    type: GET_PARTCLAIM_APPROVE_FAIL,
    message
}));
export const getPartClaimApprove = () => dispatch => {
    dispatch(getPartClaimApproveBegin());
    return api.getPartClaimApprove().then(res => {
        if(res.ok)
            dispatch(getPartClaimApproveSuccess(res.data));
        else
            dispatch(getPartClaimApproveFail());
    });
};
/*==============================箱单排柜提醒API================================= */
export const GET_PACKINGLISTCABINETAPPLY_BEGIN = 'GET_PACKINGLISTCABINETAPPLY_BEGIN';
export const GET_PACKINGLISTCABINETAPPLY_SUCCESS = 'GET_PACKINGLISTCABINETAPPLY_SUCCESS';
export const GET_PACKINGLISTCABINETAPPLY_FAIL = 'GET_PACKINGLISTCABINETAPPLY_FAIL';

const getPackingListCabinetApplyBegin = () => ({
    type: GET_PACKINGLISTCABINETAPPLY_BEGIN
});

const getPackingListCabinetApplySuccess = data => ({
    type: GET_PACKINGLISTCABINETAPPLY_SUCCESS,
    data
});

const getPackingListCabinetApplyFail = createNotificationAction(message => ({
    type: GET_PACKINGLISTCABINETAPPLY_FAIL,
    message
}));
export const getPackingListCabinetApply = () => dispatch => {
    dispatch(getPackingListCabinetApplyBegin());
    return api.getPackingListCabinetApply().then(res => {
        if(res.ok)
            dispatch(getPackingListCabinetApplySuccess(res.data));
        else
            dispatch(getPackingListCabinetApplyFail());
    });
};
/*==============================货运委托书生成提醒API================================= */
export const GET_PARTSHIPORDER_CREATE_BEGIN = 'GET_PARTSHIPORDER_CREATE_BEGIN';
export const GET_PARTSHIPORDER_CREATE_SUCCESS = 'GET_PARTSHIPORDER_CREATE_SUCCESS';
export const GET_PARTSHIPORDER_CREATE_FAIL = 'GET_PARTSHIPORDER_CREATE_FAIL';

const getPartShipOrderCreateBegin = () => ({
    type: GET_PARTSHIPORDER_CREATE_BEGIN
});

const getPartShipOrderCreateSuccess = data => ({
    type: GET_PARTSHIPORDER_CREATE_SUCCESS,
    data
});

const getPartShipOrderCreateFail = createNotificationAction(message => ({
    type: GET_PARTSHIPORDER_CREATE_FAIL,
    message
}));
export const getPartShipOrderCreate = () => dispatch => {
    dispatch(getPartShipOrderCreateBegin());
    return api.getPartShipOrderCreate().then(res => {
        if(res.ok)
            dispatch(getPartShipOrderCreateSuccess(res.data));
        else
            dispatch(getPartShipOrderCreateFail());
    });
};
/*==============================新增汇率提醒API================================= */
export const GET_EXCHANGERATE_BEGIN = 'GET_EXCHANGERATE_BEGIN';
export const GET_EXCHANGERATE_SUCCESS = 'GET_EXCHANGERATE_SUCCESS';
export const GET_EXCHANGERATE_FAIL = 'GET_EXCHANGERATE_FAIL';

const getExchangeRateBegin = () => ({
    type: GET_EXCHANGERATE_BEGIN
});

const getExchangeRateSuccess = data => ({
    type: GET_EXCHANGERATE_SUCCESS,
    data
});

const getExchangeRateFail = createNotificationAction(message => ({
    type: GET_EXCHANGERATE_FAIL,
    message
}));
export const getExchangeRate = () => dispatch => {
    dispatch(getExchangeRateBegin());
    return api.getExchangeRate().then(res => {
        if(res.ok)
            dispatch(getExchangeRateSuccess(res.data));
        else
            dispatch(getExchangeRateFail());
    });
};
/*==============================工作日历维护提醒API================================= */
export const GET_WORKINGDAY_BEGIN = 'GET_WORKINGDAY_BEGIN';
export const GET_WORKINGDAY_SUCCESS = 'GET_WORKINGDAY_SUCCESS';
export const GET_WORKINGDAY_FAIL = 'GET_WORKINGDAY_FAIL';

const getWorkingDayBegin = () => ({
    type: GET_WORKINGDAY_BEGIN
});

const getWorkingDaySuccess = data => ({
    type: GET_WORKINGDAY_SUCCESS,
    data
});

const getWorkingDayFail = createNotificationAction(message => ({
    type: GET_WORKINGDAY_FAIL,
    message
}));
export const getWorkingDay = () => dispatch => {
    dispatch(getWorkingDayBegin());
    return api.getWorkingDay().then(res => {
        if(res.ok)
            dispatch(getWorkingDaySuccess(res.data));
        else
            dispatch(getWorkingDayFail());
    });
};
/*==============================订单签收提醒API================================= */
export const GET_PARTSHIPMENT_RECEIPT_BEGIN = 'GET_PARTSHIPMENT_RECEIPT_BEGIN';
export const GET_PARTSHIPMENT_RECEIPT_SUCCESS = 'GET_PARTSHIPMENT_RECEIPT_SUCCESS';
export const GET_PARTSHIPMENT_RECEIPT_FAIL = 'GET_PARTSHIPMENT_RECEIPT_FAIL';

const getPartShipmentReceiptBegin = () => ({
    type: GET_PARTSHIPMENT_RECEIPT_BEGIN
});

const getPartShipmentReceiptSuccess = data => ({
    type: GET_PARTSHIPMENT_RECEIPT_SUCCESS,
    data
});

const getPartShipmentReceiptFail = createNotificationAction(message => ({
    type: GET_PARTSHIPMENT_RECEIPT_FAIL,
    message
}));
export const getPartShipmentReceipt = () => dispatch => {
    dispatch(getPartShipmentReceiptBegin());
    return api.getPartShipmentReceipt().then(res => {
        if(res.ok)
            dispatch(getPartShipmentReceiptSuccess(res.data.partShipment));
        else
            dispatch(getPartShipmentReceiptFail());
    });
};
/*==============================初始化API ================================= */
export const GET_INIT_DATA_BEGIN = 'GET_INIT_DATA_BEGIN';
export const GET_INIT_DATA_SUCCESS = 'GET_INIT_DATA_SUCCESS';
export const GET_INIT_DATA_FAIL = 'GET_INIT_DATA_FAIL';
const getInitDataBegin = () => ({
    type: GET_INIT_DATA_BEGIN
});

const getInitDataSuccess = data => ({
    type: GET_INIT_DATA_SUCCESS,
    data
});
const getInitDataFail = () => ({
    type: GET_INIT_DATA_FAIL
});

export const getInitData = () => dispatch => {
    dispatch(getInitDataBegin());
    const init = api.getInitData().then(res => {
        if(res.ok)
            dispatch(getInitDataSuccess(res.data));
        else
            dispatch(getInitDataFail());
        return res.ok;
    });
    const permissions = getCurrentUserPagePermissionsApi(PAGE_CODE).then(res => {
        if(res.isOk) {
            dispatch(getCurrentUserPagePermissionsSuccess(res.data));
            if(res.data.includes(PERMISSION.notification))
                dispatch(getNoticeData());
            if(res.data.includes(PERMISSION.claimSettlement))
                dispatch(getClaimSettlementData());
            if(res.data.includes(PERMISSION.expenseAdjustment))
                dispatch(getExpenseData());
            if(res.data.includes(PERMISSION.partOrderPlan))
                dispatch(getPartOrderPlanData());
            if(res.data.includes(PERMISSION.backorder))
                dispatch(getPartBackOrderData());
            if(res.data.includes(PERMISSION.partStock))
                dispatch(getPartStockData());
            if(res.data.includes(PERMISSION.workingHour))
                dispatch(getWorkItemData());
            if(res.data.includes(PERMISSION.assistPart))
                dispatch(getAssistPartData());
            if(res.data.includes(PERMISSION.servicePrice))
                dispatch(getServicePriceData());
            if(res.data.includes(PERMISSION.claimApply))
                dispatch(getClaimApplyData());
            if(res.data.includes(PERMISSION.salePlanOrderSubmit))
                dispatch(getSalePlanOrderSubmit());
            if(res.data.includes(PERMISSION.salePlanOrderApprove))
                dispatch(getSalePlanOrderApprove());
            if(res.data.includes(PERMISSION.partOrderPlanReject))
                dispatch(getPartOrderPlanReject());
            if(res.data.includes(PERMISSION.partOrderPlanApprove))
                dispatch(getPartOrderPlanApprove());
            if(res.data.includes(PERMISSION.partSaleOrderReject))
                dispatch(getPartSaleOrderReject());
            if(res.data.includes(PERMISSION.partSaleOrderApprove))
                dispatch(getPartSaleOrderApprove());
            if(res.data.includes(PERMISSION.partOrderPIConfirm))
                dispatch(getPartOrderPIConfirm());
            if(res.data.includes(PERMISSION.partOrderPIPay))
                dispatch(getPartOrderPIPay());
            if(res.data.includes(PERMISSION.partSaleOrderCreate))
                dispatch(getPartSaleOrderCreate());
            if(res.data.includes(PERMISSION.partOrderPICreate))
                dispatch(getPartOrderPICreate());
            if(res.data.includes(PERMISSION.invoiceAddKd))
                dispatch(getInvoiceAddKd());
            if(res.data.includes(PERMISSION.invoiceAddCbu))
                dispatch(getInvoiceAddCbu());
            if(res.data.includes(PERMISSION.invoiceConfirmKd))
                dispatch(getInvoiceConfirmKd());
            if(res.data.includes(PERMISSION.invoiceConfirmCbu))
                dispatch(getInvoiceConfirmCbu());
            if(res.data.includes(PERMISSION.CBUSaleOrderReject))
                dispatch(getCBUSaleOrderReject());
            if(res.data.includes(PERMISSION.KDSaleOrderReject))
                dispatch(getKDSaleOrderReject());
            if(res.data.includes(PERMISSION.saleConfirmationRejectCbu))
                dispatch(getSaleConfirmationRejectCbu());
            if(res.data.includes(PERMISSION.saleConfirmationRejectKd))
                dispatch(getSaleConfirmationRejectKd());
            if(res.data.includes(PERMISSION.partClaimReject))
                dispatch(getPartClaimReject());
            if(res.data.includes(PERMISSION.partClaimDecisionConfirm))
                dispatch(getPartClaimDecisionConfirm());
            if(res.data.includes(PERMISSION.partClaimCacuConfirm))
                dispatch(getPartClaimCacuConfirm());
            if(res.data.includes(PERMISSION.partClaimApprove))
                dispatch(getPartClaimApprove());
            if(res.data.includes(PERMISSION.packingListCabinetApply))
                dispatch(getPackingListCabinetApply());
            if(res.data.includes(PERMISSION.partShipOrderCreate))
                dispatch(getPartShipOrderCreate());
            if(res.data.includes(PERMISSION.exchangeRate))
                dispatch(getExchangeRate());
            if(res.data.includes(PERMISSION.workingDay))
                dispatch(getWorkingDay());
            if(res.data.includes(PERMISSION.partShipmentReceipt))
                dispatch(getPartShipmentReceipt());
        } else dispatch(getCurrentUserPagePermissionsFail(res.statusCode, res.message));
        return res.isOk;
    });

    return Promise.all([init, permissions]).then(values => values[0] && values[1]);
};
